﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace MvcApplicationDataHound.DataAccess
{
    public class TSD_DataAccess
    {
        public DataSet GetTsdProduct(double UpcToSearch)
        {
            try
            {
                using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DataHoundDB"].ConnectionString))
                using (var cmd = new SqlCommand("GetActivity", conn)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    cmd.Parameters.AddWithValue("@UpcToSearch", UpcToSearch);
                    using (var da = new SqlDataAdapter(cmd))
                    {
                        // Fill the DataSet using default values for DataTable names, etc
                        var dataset = new DataSet();
                        da.Fill(dataset);
                        return dataset;
                    }
                }
            }
            catch (SqlException ex)
            {
                //TODO Write Error to DataHoundDB ErrorLog
                Console.WriteLine("SQL Error SPROC call GetTsdProdcut" + ex.Message);
            }
            return null;
        }

        public void PutTsdProdcut()
        {
            try
            {
                var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataHoundDB"].ConnectionString);
                var command = new SqlCommand("sp_Test", sqlConnection) {CommandType = CommandType.StoredProcedure};
                command.Parameters.Add("@Id", SqlDbType.VarChar).Value = "SomeValue";
                command.Parameters.Add("@Name", SqlDbType.DateTime).Value = "SomeValue";
                sqlConnection.Open();
                command.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                //TODO Write Error to DataHoundDB ErrorLog
                Console.WriteLine("SQL Error SPROC call PutTsdProdcut" + ex.Message);
            }
        }
    }//EndClass
}//EndNameSpace